package com.kk.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.kk.common.lang.Result;
import com.kk.entity.User;
import com.kk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.RolesAllowed;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kk
 * @since 2020-06-11
 */
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/id/{id}")
    public Result getUser(@PathVariable("id")Long id){
        User user = userService.getById(id);
        return Result.success(user);
    }

    @GetMapping("/username/{username}")
    public Result getUserByName(@PathVariable("username")String username){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        User user = userService.getOne(wrapper);
        return Result.success(user);
    }
}

